/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Login;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author LAB1
 */
public class BOL {

    public static Users checkLogin(String account, String password) {
        DAL dal = new DAL();
        try {
            ArrayList paramlist = new ArrayList();
            paramlist.add(account);
            paramlist.add(password);
            ResultSet rs = dal.executeQuery("login", paramlist);
            if (rs.next()) {
                Users a = new Users();
                a.setIdUser(rs.getString("IDUser"));
                a.setAccount(rs.getString("Account"));
                a.setPassword(rs.getString("Password"));
                a.setEmail(rs.getString("Email"));
                a.setType(rs.getString("Type"));
                a.setFullname(rs.getString("FullName"));
                a.setBirthdate(rs.getDate("birthday"));
                a.setSex(rs.getString("sex"));
                a.setAge(rs.getInt("age"));
                a.setCity(rs.getString("City"));
                a.setAddress(rs.getString("Address"));
                a.setSecurity(rs.getString("Security"));
                a.setActive(rs.getString("active"));
                return a;
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(BOL.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(BOL.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            dal.closeConnection();
        }
        return null;
    }

    public static int changePassword(String account, String password) {
        int a = 0;
        DAL dal = new DAL();
        ArrayList ar = new ArrayList();
        ar.add(account);
        ar.add(password);
        try {
            a = dal.executeUpdateQuery("changepassword", ar);
        } catch (Exception e) {
        }
        return a;

    }
}
